﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using ContactManager.Common;

namespace ContactManager
{
    public partial class TracesForm : AlSkin.AlForm.AlBaseForm
    {
        private string contactId = "";

        public TracesForm()
        {
            InitializeComponent();
        }

        public TracesForm(string contactId)
        {
            this.contactId = contactId;
            InitializeComponent();
        }
        
        private void TracesForm_Load(object sender, EventArgs e)
        {
            //通过ID获取客户信息，填充表单，设置表单为不可编辑
            if (contactId.Length == 0)
            {
                MessageBox.Show("抱歉，出错，系统初始化失败，请重试 ","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            string findSql = "select * from contacters t where t.c_id = ?";
            OleDbParameter[] parameters = { new OleDbParameter("@c_id", Convert.ToInt32(this.contactId)) };
            DataSet ds = AccessHelper.ExecuteQuery(findSql, parameters);
            //初始化值
            string name = Convert.ToString(ds.Tables[0].Rows[0]["c_name"]);
            string pname = Convert.ToString(ds.Tables[0].Rows[0]["c_pname"]);
            DateTime birthday = Convert.ToDateTime(ds.Tables[0].Rows[0]["c_birthday"]);
            string company = Convert.ToString(ds.Tables[0].Rows[0]["c_company"]);
            string title = Convert.ToString(ds.Tables[0].Rows[0]["c_title"]);
            string qq = Convert.ToString(ds.Tables[0].Rows[0]["c_qq"]);
            string msn = Convert.ToString(ds.Tables[0].Rows[0]["c_msn"]);
            string phone1 = Convert.ToString(ds.Tables[0].Rows[0]["c_phone_one"]);
            string phone2 = Convert.ToString(ds.Tables[0].Rows[0]["c_phone_second"]);
            string mail = Convert.ToString(ds.Tables[0].Rows[0]["c_email"]);
            string cphone = Convert.ToString(ds.Tables[0].Rows[0]["c_company_phone"]);
            string url = Convert.ToString(ds.Tables[0].Rows[0]["c_url"]);
            string hobby = Convert.ToString(ds.Tables[0].Rows[0]["c_hobby"]);
            string address = Convert.ToString(ds.Tables[0].Rows[0]["c_address"]);
            int groupId = Convert.ToInt32(ds.Tables[0].Rows[0]["c_group_id"]);
            string groupName = Convert.ToString(AccessHelper.ExecuteQuery("select g_name from groups where g_id =" + groupId).Tables[0].Rows[0]["g_name"]);
            string promary = "";
            string city = "";
            string addressDetail = "";
            if (address != "," && address.Length > 1)
            {
                promary = address.Split(',')[0];
                city = address.Split(',')[1];
                addressDetail = address.Split(',')[2];
            }
            //控件初始化
            string groupSql = "select * from groups t";
            DataSet groupDs = AccessHelper.ExecuteQuery(groupSql);
            foreach (DataRow dr in groupDs.Tables[0].Rows)
            {
                ComboBoxItem group = new ComboBoxItem();
                group.Text = dr["g_name"].ToString();
                group.Value = dr["g_id"];
                this.combGroup.Items.Add(group);
            }

            string promarySql = "select proName from promary";
            DataSet promaryDs = AccessHelper.ExecuteQuery(promarySql);
            foreach (DataRow dr in promaryDs.Tables[0].Rows)
            {
                this.combPromary.Items.Add(dr["proName"]);
            }

            this.labelContactName.Text = Constant.TITLE + GlobleUser.USER_NAME;

            this.txtName.Text = name;
            this.txtName.Enabled = false;

            this.txtPname.Text = pname;
            this.txtPname.Enabled = false;

            this.dtpBirthday.Value = birthday;
            this.dtpBirthday.Enabled = false;

            this.txtCompany.Text = company;
            this.txtCompany.Enabled = false;

            this.txtTitle.Text = title;
            this.txtTitle.Enabled = false;

            this.txtQQ.Text = qq;
            this.txtQQ.Enabled = false;

            this.txtMSN.Text = msn;
            this.txtMSN.Enabled = false;

            this.txtPhone1.Text = phone1;
            this.txtPhone1.Enabled = false;

            this.txtPhone2.Text = phone2;
            this.txtPhone2.Enabled = false;

            this.txtMail.Text = mail;
            this.txtMail.Enabled = false;

            this.txtCompanyPhone.Text = cphone;
            this.txtCompanyPhone.Enabled = false;

            this.txtUrl.Text = url;
            this.txtUrl.Enabled = false;

            this.txtHobby.Text = hobby;
            this.txtHobby.Enabled = false;

            this.combGroup.Text = groupName;
            this.combGroup.Enabled = false;

            this.combPromary.Text = promary;
            this.combPromary.Enabled = false;

            this.combCity.Text = city;
            this.combCity.Enabled = false;

            this.txtAddressDetail.Text = addressDetail;
            this.txtAddressDetail.Enabled = false;
            initTraceGridView(null);//初始化tracegrid

            //初始化追踪表单
            this.dtpTraceNextTime.Value = DateTime.Now;
            this.dtpTraceTime.Value = DateTime.Now;
            this.dtpSumStart.Value = DateTime.Now;
            this.dtpSumEnd.Value = DateTime.Now;

            //算合计
            getSum(null);

            //初始化最近联系人
            this.combRecent.Items.Clear();
            string recentSql = "select top 18 c.c_id,c.c_name,max(t.t_time) from contacters c,traces t where c.c_id = t.t_c_id group by c.c_id,c.c_name order by max(t.t_time) desc";
            DataSet recentDs = AccessHelper.ExecuteQuery(recentSql);
            foreach(DataRow dr in recentDs.Tables[0].Rows)
            {
                ComboBoxItem ci = new ComboBoxItem();
                ci.Text =Convert.ToString(dr["c_name"]);
                ci.Value = dr["c_id"];
                this.combRecent.Items.Add(ci);
            }
        
        }

        private void TracesForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("您确定要退出吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
            {
                this.Dispose();
                this.Close();
            }
            else
            {
                e.Cancel = true;
            }
        }

        private void combPromary_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.combCity.Items.Clear();
            string sql = "select cityName from city,promary where city.proID=promary.proID and promary.proName='" + this.combPromary.Text.Trim() + "'";
            DataSet ds = AccessHelper.ExecuteQuery(sql);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                this.combCity.Items.Add(dr["cityName"]);
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            this.txtName.Enabled = true;

            this.txtPname.Enabled = true;

            this.dtpBirthday.Enabled = true;

            this.txtCompany.Enabled = true;

            this.txtTitle.Enabled = true;

            this.txtQQ.Enabled = true;

            this.txtMSN.Enabled = true;

            this.txtPhone1.Enabled = true;

            this.txtPhone2.Enabled = true;

            this.txtMail.Enabled = true;

            this.txtCompanyPhone.Enabled = true;

            this.txtUrl.Enabled = true;

            this.txtHobby.Enabled = true;

            this.combGroup.Enabled = true;

            this.combPromary.Enabled = true;

            this.combCity.Enabled = true;

            this.txtAddressDetail.Enabled = true;

            this.btnSave.Enabled = true;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string name = this.txtName.Text.Trim();
            string pname = this.txtPname.Text.Trim();
            DateTime birthday = this.dtpBirthday.Value;
            string company = this.txtCompany.Text.Trim();
            string title = this.txtTitle.Text.Trim();
            string qq = this.txtQQ.Text.Trim();
            string msn = this.txtMSN.Text.Trim();
            string phone1 = this.txtPhone1.Text.Trim();
            string phone2 = this.txtPhone2.Text.Trim();
            string mail = this.txtMail.Text.Trim();
            string cphone = this.txtCompanyPhone.Text.Trim();
            string url = this.txtUrl.Text.Trim();
            string hobby = this.txtHobby.Text.Trim();
            string address = this.combPromary.Text.Trim() + "," + this.combCity.Text.Trim() + "," + this.txtAddressDetail.Text.Trim();
            int groupId = Convert.ToInt32(((ComboBoxItem)this.combGroup.SelectedItem).Value);

            string sql = "update contacters set c_name = ?,c_pname = ?,c_company = ?,c_title = ?,c_qq = ?,c_msn = ?,c_phone_one = ?,c_phone_second = ?,c_email = ?,c_company_phone = ?,c_url = ?,c_hobby = ?,c_address = ?,c_group_id = ?,c_birthday = #" + birthday.ToString("yyyy/MM/dd HH:mm:ss") + "# where c_id = ?";
            OleDbParameter[] parameters = {new OleDbParameter("@c_name",name),
                                               new OleDbParameter("@c_pname",pname),
                                               new OleDbParameter("@c_company",company),
                                               new OleDbParameter("@c_title",title),
                                               new OleDbParameter("@c_qq",qq),
                                               new OleDbParameter("@c_msn",msn),
                                               new OleDbParameter("@c_phone_one",phone1),
                                               new OleDbParameter("@c_phone_second",phone2),
                                               new OleDbParameter("@c_email",mail),
                                               new OleDbParameter("@c_company_phone",cphone),
                                               new OleDbParameter("@c_url",url),
                                               new OleDbParameter("@c_hobby",hobby),
                                               new OleDbParameter("@c_address",address),
                                               new OleDbParameter("@c_group_id",groupId),
                                               new OleDbParameter("@c_id",Convert.ToInt32(contactId))
                                              };
            if (AccessHelper.ExecuteNonQuery(sql, parameters) > 0)
            {
                MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.TracesForm_Load(this, null);
            }
            else
            {
                MessageBox.Show("修改失败,请重启程序重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }

        private void dataGridViewTrace_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewTrace.CurrentRow != null)
            {
                this.dtpTraceTime.Value = Convert.ToDateTime(this.dataGridViewTrace.CurrentRow.Cells["TraceTime"].Value);
                this.txtTraceContent.Text = this.dataGridViewTrace.CurrentRow.Cells["TraceContent"].Value.ToString();
                this.txtTraceDeal.Text = this.dataGridViewTrace.CurrentRow.Cells["TraceDeal"].Value.ToString();
                this.txtTraceCost.Text = this.dataGridViewTrace.CurrentRow.Cells["TraceCost"].Value.ToString();
                this.dtpTraceNextTime.Value = Convert.ToDateTime(this.dataGridViewTrace.CurrentRow.Cells["TraceNextTime"].Value);
                this.txtTraceNextContent.Text = this.dataGridViewTrace.CurrentRow.Cells["TraceNextContent"].Value.ToString();
                this.txtTraceIncome.Text = this.dataGridViewTrace.CurrentRow.Cells["TraceIncome"].Value.ToString();
                initTraceFormEnable(false);
            }
        }

        private void btnTraceFind_Click(object sender, EventArgs e)
        {
            DateTime ftime = this.dtpTraceTime.Value;
            string fcontent = this.txtTraceContent.Text.Trim();
            string fdeal = this.txtTraceDeal.Text.Trim();
            string fcost = this.txtTraceCost.Text.Trim();
            string fincome = this.txtTraceIncome.Text.Trim();
            DateTime fnextTime = this.dtpTraceNextTime.Value;
            string fnextcontent = this.txtTraceNextContent.Text.Trim();

            if (this.txtTraceContent.Enabled == true)
            { 
                //判断是否为非编辑状态
                StringBuilder sb = new StringBuilder("select * from traces where t_c_id =" + contactId);

                if (fcontent.Length > 0)
                {
                    sb.Append(" and t_content like '%" + fcontent + "%'");
                }

                if (fnextcontent.Length > 0)
                {
                    sb.Append(" and t_next_content like '%" + fnextcontent + "%'");
                }

                if (fdeal.Length > 0)
                {
                    sb.Append(" and t_deal =" + fdeal);
                }

                if (fcost.Length > 0)
                {
                    sb.Append(" and t_cost =" + fcost);
                }

                if (fincome.Length > 0)
                {
                    sb.Append(" and t_income =" + fincome);
                }

                DataSet ds = AccessHelper.ExecuteQuery(sb.ToString());
                this.dataGridViewTrace.Rows.Clear();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int id = Convert.ToInt32(dr["t_id"]);
                    int count = Convert.ToInt32(dr["t_count"]);
                    string time = Convert.ToDateTime(dr["t_time"]).ToString("yyyy/MM/dd HH:mm:ss");
                    string content = Convert.ToString(dr["t_content"]);
                    double deal = Convert.ToDouble(dr["t_deal"]);
                    double cost = Convert.ToDouble(dr["t_cost"]);
                    double income = Convert.ToDouble(dr["t_income"]);
                    string nextTime = Convert.ToDateTime(dr["t_next_time"]).ToString("yyyy/MM/dd HH:mm:ss");
                    string nextContent = Convert.ToString(dr["t_next_content"]);
                    this.dataGridViewTrace.Rows.Add(id, count, time, content, deal, cost, income, nextTime, nextContent);
                }

            }

            
        }

        private void btnTraceAdd_Click(object sender, EventArgs e)
        {
            //获取次数
            int count = 1;
            string sql = "select max(t_count) from traces where t_c_id =" + contactId;
            DataSet countDs = AccessHelper.ExecuteQuery(sql);
            if (countDs.Tables[0].Rows[0][0].ToString().Length > 0)
            {
                count = Convert.ToInt32(countDs.Tables[0].Rows[0][0].ToString()) + 1;
            }
            DateTime ftime = this.dtpTraceTime.Value;
            string fcontent = this.txtTraceContent.Text.Trim();
            string fdeal = this.txtTraceDeal.Text.Trim().Length == 0 ? "0" : this.txtTraceDeal.Text.Trim();
            string fcost = this.txtTraceCost.Text.Trim().Length == 0 ? "0" : this.txtTraceCost.Text.Trim();
            string fincome = this.txtTraceIncome.Text.Trim().Length == 0 ? "0" : this.txtTraceIncome.Text.Trim();
            DateTime fnextTime = this.dtpTraceNextTime.Value;
            string fnextcontent = this.txtTraceNextContent.Text.Trim();

            if (this.txtTraceContent.Enabled == true)
            {

                if (fcontent.Length == 0)
                {
                    MessageBox.Show("访谈内容不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                

                if (DialogResult.Yes == MessageBox.Show("确认添加吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    string addSql = "insert into traces(t_content,t_deal,t_cost,t_income,t_next_content,t_count,t_c_id,t_time,t_next_time) values(?,?,?,?,?,?,?,#" + ftime.ToString("yyyy/MM/dd HH:mm:ss") + "#,#" + fnextTime.ToString("yyyy/MM/dd HH:mm:ss") + "#)";
                    OleDbParameter[] parameters = {
                                               new OleDbParameter("@t_content",fcontent),
                                               new OleDbParameter("@t_deal",fdeal),
                                               new OleDbParameter("@t_cost",fcost),
                                               new OleDbParameter("@t_income",fincome),
                                               new OleDbParameter("@t_next_content",fnextcontent),
                                               new OleDbParameter("@t_count",count),
                                               new OleDbParameter("@t_c_id",contactId)
                                              };
                    if (AccessHelper.ExecuteNonQuery(addSql, parameters) > 0)
                    {
                        MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.btnTraceReset_Click(this, null);
                        this.TracesForm_Load(this, null);
                    }
                    else
                    {
                        MessageBox.Show("添加失败，请重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }

        }

        private void btnTraceReset_Click(object sender, EventArgs e)
        {
            initTraceFormEnable(true);

            this.dtpTraceTime.Value = DateTime.Now;
            this.txtTraceContent.Text = "";
            this.txtTraceDeal.Text = "";
            this.txtTraceCost.Text = "";
            this.txtTraceIncome.Text = "";
            this.txtTraceIncome.Text = "";
            this.dtpTraceNextTime.Value = DateTime.Now;
            this.txtTraceNextContent.Text = "";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DateTime ftime = this.dtpTraceTime.Value;
            string fcontent = this.txtTraceContent.Text.Trim();
            string fdeal = this.txtTraceDeal.Text.Trim();
            string fcost = this.txtTraceCost.Text.Trim();
            string fincome = this.txtTraceIncome.Text.Trim();
            DateTime fnextTime = this.dtpTraceNextTime.Value;
            string fnextcontent = this.txtTraceNextContent.Text.Trim();
            if (dataGridViewTrace.CurrentRow != null)
            {
                string editSql = "update traces set t_content=?,t_deal=?,t_cost=?,t_income=?,t_next_content=?,t_time = #" + ftime.ToString("yyyy/MM/dd HH:mm:ss") + "#,t_next_time=#" + fnextTime.ToString("yyyy/MM/dd HH:mm:ss") + "# where t_id = ?";
                OleDbParameter[] parameters = {
                                            new OleDbParameter("@t_content",fcontent),
                                            new OleDbParameter("@t_deal",fdeal),
                                            new OleDbParameter("@t_cost",fcost),
                                            new OleDbParameter("@t_income",fincome),
                                            new OleDbParameter("@t_next_content",fnextcontent),
                                            new OleDbParameter("@t_id",dataGridViewTrace.CurrentRow.Cells[0].Value)
                                            };
                if (AccessHelper.ExecuteNonQuery(editSql, parameters) > 0)
                {
                    MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.btnTraceFind_Click(this, null);
                    this.TracesForm_Load(this, null);
                    this.btnTraceReset_Click(this, null);

                    this.btnTraceFind.Enabled = true;
                    this.btnTraceAdd.Enabled = true;
                    this.btnTraceReset.Enabled = true;
                    this.btnOK.Enabled = false;
                }
                else
                {
                    MessageBox.Show("修改失败，请重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }  
            }
            
           
        }

        private void btnTraceEdit_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewTrace.CurrentRow != null)
            {
                this.dataGridViewTrace_Click(this, null);
                initTraceFormEnable(true);
                this.btnTraceFind.Enabled = false;
                this.btnTraceAdd.Enabled = false;
                this.btnTraceReset.Enabled = false;
                this.btnOK.Enabled = true;
            }
        }

        private void DelteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string delSql = "delete * from traces where t_id = " + dataGridViewTrace.CurrentRow.Cells["TraceId"].Value.ToString();
            if (DialogResult.Yes == MessageBox.Show("确实要删除此记录吗？。", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
            {
                if (AccessHelper.ExecuteNonQuery(delSql) > 0)
                {
                    MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.TracesForm_Load(this, null);
                    this.btnTraceReset_Click(this, null);
                }
                else
                {
                    MessageBox.Show("删除失败，请重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }

        private void combRecent_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBoxItem recent = (ComboBoxItem)this.combRecent.SelectedItem;
            this.contactId = Convert.ToString(recent.Value);
            this.TracesForm_Load(this, null);
        }

        private void dtpSumEnd_CloseUp(object sender, EventArgs e)
        {
            if (DateTime.Compare(this.dtpSumEnd.Value, this.dtpSumStart.Value) < 0)
            {
                MessageBox.Show("结束时间不能大于开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.dtpSumEnd.Value = DateTime.Now;
                this.dtpSumStart.Value = DateTime.Now;
                return;
            }
            string sql = " and t_time >= #" + this.dtpSumStart.Value.ToString("yyyy/MM/dd HH:mm:ss") + "# and t_time <= #" + this.dtpSumEnd.Value.ToString("yyyy/MM/dd HH:mm:ss") + "# ";
            initTraceGridView(sql);
            getSum(sql);
        }

        private void dtpSumStart_CloseUp(object sender, EventArgs e)
        {
            if (DateTime.Compare(this.dtpSumEnd.Value, this.dtpSumStart.Value) < 0)
            {
                MessageBox.Show("结束时间不能大于开始时间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.dtpSumEnd.Value = DateTime.Now;
                this.dtpSumStart.Value = DateTime.Now;
                return;
            }
            string sql = " and t_time >= #" + this.dtpSumStart.Value.ToString("yyyy/MM/dd HH:mm:ss") + "# and t_time <= #" + this.dtpSumEnd.Value.ToString("yyyy/MM/dd HH:mm:ss") + "# ";
            initTraceGridView(sql);
            getSum(sql);
        }

        private void initTraceFormEnable(Boolean flag)//设置trace表单的enable属性
        {
            this.txtTraceContent.Enabled = flag;
            this.txtTraceCost.Enabled = flag;
            this.txtTraceDeal.Enabled = flag;
            this.txtTraceNextContent.Enabled = flag;
            this.dtpTraceNextTime.Enabled = flag;
            this.dtpTraceTime.Enabled = flag;
            this.txtTraceIncome.Enabled = flag;
        }

        private void initTraceGridView(string sql) //传入where 条件
        {
            //初始化追踪表格
            this.dataGridViewTrace.Rows.Clear();
            string traceSql = "select * from traces where t_c_id = " + contactId + sql + " order by t_count desc";
            DataSet traceDs = AccessHelper.ExecuteQuery(traceSql);
            foreach (DataRow dr in traceDs.Tables[0].Rows)
            {
                int id = Convert.ToInt32(dr["t_id"]);
                int count = Convert.ToInt32(dr["t_count"]);
                string time = Convert.ToDateTime(dr["t_time"]).ToString("yyyy/MM/dd HH:mm");
                string content = Convert.ToString(dr["t_content"]);
                double deal = Convert.ToDouble(dr["t_deal"]);
                double cost = Convert.ToDouble(dr["t_cost"]);
                double income = Convert.ToDouble(dr["t_income"]);
                string nextTime = Convert.ToDateTime(dr["t_next_time"]).ToString("yyyy/MM/dd HH:mm");
                string nextContent = Convert.ToString(dr["t_next_content"]);
                this.dataGridViewTrace.Rows.Add(id, count, time, content, deal, cost, income, nextTime, nextContent);
            }
        }

        private void getSum(string sql)//算合计，传入and条件sql
        {
            string sumSql = "select sum(t_deal) as deal,sum(t_cost) as cost,sum(t_income) as income from traces where t_c_id =" + contactId + sql;
            DataSet sumDs = AccessHelper.ExecuteQuery(sumSql);
            this.labDealSum.Text = "交易额合计：" + sumDs.Tables[0].Rows[0]["deal"].ToString();
            this.labCostSum.Text = "支出合计：" + sumDs.Tables[0].Rows[0]["cost"].ToString();
            this.labIncomeSum.Text = "收入合计：" + sumDs.Tables[0].Rows[0]["income"].ToString();
        }

        private void txtTraceDeal_KeyPress(object sender, KeyPressEventArgs e)
        {
            checkNumTextBox(sender, e);
        }

        private void txtTraceCost_KeyPress(object sender, KeyPressEventArgs e)
        {
            checkNumTextBox(sender, e);
        }

        private void txtTraceIncome_KeyPress(object sender, KeyPressEventArgs e)
        {
            checkNumTextBox(sender, e);
        }

        private static void checkNumTextBox(object sender, KeyPressEventArgs e)
        {
            //验证数字输入，只能输入数字和小数点
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1) e.Handled = true;
                }
                else e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }

            }
        }

        private static void checkTextBox(KeyPressEventArgs e)
        {
            if (((e.KeyChar < (char)48) || (e.KeyChar > (char)57)) && e.KeyChar != 8)
            {
                e.Handled = true;
            }
        }

        private void txtQQ_KeyPress(object sender, KeyPressEventArgs e)
        {
            checkTextBox(e);
        }

        private void txtPhone1_KeyPress(object sender, KeyPressEventArgs e)
        {
            checkTextBox(e);
        }

        private void txtPhone2_KeyPress(object sender, KeyPressEventArgs e)
        {
            checkTextBox(e);
        }


    }
}
